<template>
  <div class="list" >
    <div class="article_item" v-for="(item,index) in mylist" :key="index">
      <h3 class="van-ellipsis">{{item.title}}</h3>
      <div class="img_box">
        <img src="@/assets/back.jpg" class="w100" />
      </div>

      <div class="info_box">
        <span>{{item.aut_name}}</span>
        <span>{{item.comm_count}}评论</span>
        <span>{{item.pubdate}}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  computed: {
    ...mapGetters(["currentCatagtory",'allDate']),
    // 当前选中频道下的数据源
    mylist:function(){
      return this.allDate[this.currentCatagtory] || []  //获取新闻数据
    }
    // created() {},

  },
  watch: {
    currentCatagtory: function (newval) {     // newval 是当侦听器被触发时返回的值
    if(this.allDate[this.currentCatagtory]) {   // 优化 , 如果新闻数组里面已经有了这个元素,就不发送请求, 直接用原来的
      return
    }
      this.gitNewList(newval);
    },
  },
  methods: {
    ...mapActions({ gitNewList: "newlist/gitNewList" }),
  },
};
</script>